//
//  Singleton.m
//  UI09_UITableView
//
//  Created by yutao on 15/10/21.
//  Copyright © 2015年 yutao. All rights reserved.
//

#import "Singleton.h"
#import "Student.h"
@implementation Singleton

+(instancetype)shareSingleton
{
    static Singleton *singleton = nil;

    if (singleton == nil) {

        singleton = [[Singleton alloc] init];
        //self在+号方法里代表当前的类
        [singleton createStudentDic];

    }
    return singleton;
}



-(void)createStudentDic
{

    //张建
    NSMutableDictionary *dic1 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"张健", @"name", @"男",@"gender",nil];
    //张婷
    NSMutableDictionary *dic2 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"张婷", @"name", @"女",@"gender",nil];
    NSMutableArray *zArray = [NSMutableArray arrayWithObjects:dic1, dic2,nil];

    //王鑫
    NSMutableDictionary *dic3 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"王鑫", @"name", @"男",@"gender",nil];
    //王雪飞
    NSMutableDictionary *dic4 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"王雪飞", @"name", @"女",@"gender",nil];

    NSMutableArray *wArray = [NSMutableArray arrayWithObjects:dic3, dic4,nil];

    //最外层大字典
    NSMutableDictionary *bigDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:zArray, @"Z", wArray, @"W",nil];

    NSLog(@"bigDic = %@",bigDic);


//    model

    //将大字典扒开,取到小字典里学生的信息,并赋值给model对象

    //创建最外层大字典
    self.studentDic = [NSMutableDictionary dictionary];

    for (NSString *key in bigDic) {

        //根据key取出对应的数组
        NSMutableArray *array = [bigDic objectForKey:key];

        //创建一个新的数组,存model对象
        NSMutableArray *stuArray = [NSMutableArray array];

        for (NSMutableDictionary *dic in array) {
    //一个Student对象对应一个学生小字典
            Student *stu = [[Student alloc] init];
           stu.name = [dic objectForKey:@"name"];
         stu.gender = [dic objectForKey:@"gender"];

            //将model对象存入数组中
            [stuArray addObject:stu];
            [stu release];
        }

        //大字典赋值
        [self.studentDic setObject:stuArray forKey:key];

    }




    


}



@end









